import {
  echartValT,
  flawMapT,
  flawTypeCommonT,
  flawTypeCountSymbol,
  flawTypeIdT,
  FlawTypeSiteT,
  flawTypeT,
  layerFlawMapDotT,
  layerFlawMapEchartValT,
  markingBackT,
  marklotDataT,
  treeSelectOptionType,
  valLabT
} from '@/typings/global';
import { message } from 'antd';
import { ColumnType } from 'antd/lib/table';
import markingStore from '@/stores/marking';
import { UNIT_TO_M } from './constant';

/**
 *把config的mode类型--处理成treeData多选的格式
 * @param modelTypeList
 * @returns treeData多选的格式 == Array<{ value: string; title: string children:[] }>
 */
export function handleModeType(modelTypeList: Array<any>) {
  const treeDataArr: Array<treeSelectOptionType> = [];
  const notGoodFatherMap: Map<string, Array<number>> = new Map(); //获取父-对应-子的数组key的map结构
  const allNotGoodType: Array<number> = []; // 获取所有mode下的keys

  modelTypeList.forEach(item => {
    if (!item.children || !item.children.length) {
      treeDataArr.push({
        value: item.id,
        title: item.model
      });

      notGoodFatherMap.set(item.model, []);
    } else {
      const temp1 = [] as Array<treeSelectOptionType>;
      const temp2 = [] as Array<number>;
      item.children.forEach((val: { id: any; markingName: any }) => {
        temp1.push({ value: val.id, title: val.markingName });
        temp2.push(val.id);
      });

      notGoodFatherMap.set(item.model, temp2);
      allNotGoodType.push(...temp2);
      treeDataArr.push({
        value: item.model,
        title: item.model,
        children: temp1
      });
    }
  });
  return {
    modeTreeData: treeDataArr,
    allNotGoodFatherMap: notGoodFatherMap,
    allNotGoodType: allNotGoodType
  };
}

// 字段展示的option
export function getMarkFieldOption(markField: Record<string, valLabT>) {
  const fieldOption: Array<valLabT> = [];
  Object.keys(markField).forEach(key => {
    fieldOption.push(markField[key]);
  });

  return fieldOption;
}

// 警告的消息
export function MessageWaring(content: string, ms?: number) {
  message.warning(content, ms ? ms : 1);
}
// 成功的消息
export function MessageSuccess(content: string, ms?: number) {
  message.success(content, ms ? ms : 1);
}

// 失败的消息
export function MessageError(content: string, ms?: number) {
  message.error(content, ms ? ms : 1);
}
// 一般的消息
export function MessageInfo(content: string, ms?: number) {
  message.info(content, ms ? ms : 1);
}

// marking展开后的头部
export const markSlitColumns = (data: marklotDataT[], markingFieldChecked: Record<string, any>) => {
  const handleOnCell = (index, spanMap) => {
    if (spanMap.has(index)) {
      return { rowSpan: spanMap.get(index) };
    } else {
      return {
        rowSpan: 0
      };
    }
  };
  //相关具体数据的rowSpan映射map
  const indexSpanMap = {} as Record<string, Map<number, number>>;

  const lotSpanMap = new Map();
  const lotMap = new Map();

  //按照lot来设计map
  data?.forEach(item => {
    if (lotMap.has(item.lotId)) {
      const lotList = lotMap.get(item.lotId);
      lotMap.set(item.lotId, [...lotList, item]);
    } else {
      lotMap.set(item.lotId, [item]);
    }
  });

  //按照model来设计，并对数据进行重组
  let tableData = [] as marklotDataT[];
  const modelSpanMap = new Map();
  let lotIndex = 0;
  let modelIndex = 0;
  lotMap.forEach((lotMapValue, key) => {
    lotSpanMap.set(lotIndex, lotMapValue.length);
    lotIndex += lotMapValue.length;
    const modelMap = new Map();
    lotMapValue.forEach(item => {
      if (modelMap.has(item.model)) {
        modelMap.set(item.model, [...modelMap.get(item.model), item]);
      } else {
        modelMap.set(item.model, [item]);
      }
    });
    for (let modelMapValue of modelMap.values()) {
      modelSpanMap.set(modelIndex, modelMapValue.length);
      modelIndex += modelMapValue.length;
      //对于同一lot块数据中对于不同model可能不在同一个地方，所以需要对数据进行重组
      tableData = [...tableData, ...modelMapValue];
    }
  });
  // span为总数据条数
  const allSum = new Map();
  allSum.set(0, data.length);
  indexSpanMap.allSum = allSum;
  // 根据lot来进行span映射
  indexSpanMap.lotSpanMap = lotSpanMap;
  // 根据model来进行span映射
  indexSpanMap.modelSpanMap = modelSpanMap;

  if (markingFieldChecked.hasOwnProperty('layerId')) {
    markingFieldChecked['layerId'].onCell = (_, index) => handleOnCell(index, indexSpanMap.allSum);
  }
  if (markingFieldChecked.hasOwnProperty('grad')) {
    markingFieldChecked['grad'].onCell = (_, index) => handleOnCell(index, indexSpanMap.allSum);
  }
  if (markingFieldChecked.hasOwnProperty('lotId')) {
    markingFieldChecked['lotId'].onCell = (_, index) => handleOnCell(index, indexSpanMap.lotSpanMap);
  }
  if (markingFieldChecked.hasOwnProperty('dimensionsSize')) {
    markingFieldChecked['dimensionsSize'].onCell = (_, index) => handleOnCell(index, indexSpanMap.lotSpanMap);
  }
  if (markingFieldChecked.hasOwnProperty('lotHeight')) {
    markingFieldChecked['lotHeight'].onCell = (_, index) => handleOnCell(index, indexSpanMap.lotSpanMap);
  }
  if (markingFieldChecked.hasOwnProperty('yield')) {
    markingFieldChecked['yield'].onCell = (_, index) => handleOnCell(index, indexSpanMap.lotSpanMap);
  }
  if (markingFieldChecked.hasOwnProperty('markingSum')) {
    markingFieldChecked['markingSum'].onCell = (_, index) => handleOnCell(index, indexSpanMap.lotSpanMap);
  }
  if (markingFieldChecked.hasOwnProperty('polMarkingSum')) {
    markingFieldChecked['polMarkingSum'].onCell = (_, index) => handleOnCell(index, indexSpanMap.lotSpanMap);
  }
  if (markingFieldChecked.hasOwnProperty('polPositionExactSum')) {
    markingFieldChecked['polPositionExactSum'].onCell = (_, index) => handleOnCell(index, indexSpanMap.lotSpanMap);
  }
  if (markingFieldChecked.hasOwnProperty('polPositionExactRatio')) {
    markingFieldChecked['polPositionExactRatio'].onCell = (_, index) => handleOnCell(index, indexSpanMap.lotSpanMap);
  }
  if (markingFieldChecked.hasOwnProperty('polPatternExactSum')) {
    markingFieldChecked['polPatternExactSum'].onCell = (_, index) => handleOnCell(index, indexSpanMap.lotSpanMap);
  }
  if (markingFieldChecked.hasOwnProperty('polPatternExactRatio')) {
    markingFieldChecked['polPatternExactRatio'].onCell = (_, index) => handleOnCell(index, indexSpanMap.lotSpanMap);
  }
  if (markingFieldChecked.hasOwnProperty('polPiantiehouOkSum')) {
    markingFieldChecked['polPiantiehouOkSum'].onCell = (_, index) => handleOnCell(index, indexSpanMap.lotSpanMap);
  }
  if (markingFieldChecked.hasOwnProperty('polPiantiehouOkRatio')) {
    markingFieldChecked['polPiantiehouOkRatio'].onCell = (_, index) => handleOnCell(index, indexSpanMap.lotSpanMap);
  }
  if (markingFieldChecked.hasOwnProperty('model')) {
    markingFieldChecked['model'].onCell = (_, index) => handleOnCell(index, indexSpanMap.modelSpanMap);
  }

  const columns = Object.values(markingFieldChecked) as ColumnType<any>;

  return { columns, tableData };
};

// excel导出
export const excelDataAndMergeConf = (data: marklotDataT[], markingFieldChecked: Record<string, any>) => {
  // console.log('data===>', JSON.parse(JSON.stringify(data)));
  // console.log('markingFieldChecked===>', JSON.parse(JSON.stringify(markingFieldChecked)));
  // 需要对已选择的字段进行排序
  // 默认顺序
  const defaultSort = [
    'layerId',
    'grad',
    'lotId',
    'dimensionsSize',
    'lotHeight',
    'yield',
    'markingSum',
    'polMarkingSum',
    'polPositionExactSum',
    'polPositionExactRatio',
    'polPatternExactSum',
    'polPatternExactRatio',
    'polPiantiehouOkSum',
    'polPiantiehouOkRatio',
    'model',
    'markingType',
    'markingCount',
    'markingExactCount',
    'markingExactRatio',
    'piantiehouNgPanelMarkingSum',
    'polCheckCount',
    'polCheckRatio',
    'polMissCount',
    'polMissRatio',
    'markingOverCount',
    'markingOverRatio'
  ];
  const sortedFieldChecked = {};
  defaultSort.forEach(field => {
    if (markingFieldChecked[field]) {
      sortedFieldChecked[field] = markingFieldChecked[field];
    }
  });
  // console.log('排序后的列表头', sortedFieldChecked);
  const result = {
    mergeConf: {},
    data: []
  } as any;
  //相关具体数据的rowSpan映射map
  const indexSpanMap = {} as Record<string, Map<number, number>>;

  const lotSpanMap = new Map();
  const lotMap = new Map();

  //按照lot来设计map
  data?.forEach(item => {
    if (lotMap.has(item.lotId)) {
      const lotList = lotMap.get(item.lotId);
      lotMap.set(item.lotId, [...lotList, item]);
    } else {
      lotMap.set(item.lotId, [item]);
    }
  });

  // console.log('lotMap', lotMap);
  //按照model来设计，并对数据进行重组
  let tableData = [] as marklotDataT[];
  const modelSpanMap = new Map();
  // excel表的开始行
  const baseRowIndex = 4;
  // excel表的开始列
  const baseColumnIndex = 1;
  let lotIndex = baseRowIndex + 1;
  let modelIndex = baseRowIndex + 1;
  lotMap.forEach((lotMapValue, key) => {
    lotSpanMap.set(lotIndex, lotMapValue.length - 1);
    lotIndex += lotMapValue.length;
    const modelMap = new Map();
    lotMapValue.forEach(item => {
      if (modelMap.has(item.model)) {
        modelMap.set(item.model, [...modelMap.get(item.model), item]);
      } else {
        modelMap.set(item.model, [item]);
      }
    });
    for (let modelMapValue of modelMap.values()) {
      modelSpanMap.set(modelIndex, modelMapValue.length - 1);
      modelIndex += modelMapValue.length;
      //对于同一lot块数据中对于不同model可能不在同一个地方，所以需要对数据进行重组
      tableData = [...tableData, ...modelMapValue];
    }
  });
  // span为总数据条数
  const allSum = new Map();
  allSum.set(baseRowIndex + 1, data.length - 1);
  indexSpanMap.allSum = allSum;

  // 根据lot来进行span映射
  indexSpanMap.lotSpanMap = lotSpanMap;
  // 根据model来进行span映射
  indexSpanMap.modelSpanMap = modelSpanMap;
  // console.log('=>>>>>>', indexSpanMap.allSum, indexSpanMap.lotSpanMap, indexSpanMap.modelSpanMap);
  // 找到已选择的字段对应的位置
  const checkedFieldList = Object.keys(sortedFieldChecked);

  // 单元格合并配置
  const mergeConf = [] as any;
  if (data && data.length > 0) {
    Object.keys(markingFieldChecked)?.forEach(field => {
      if (field == 'layerId' || field == 'grad') {
        indexSpanMap.allSum.forEach((span, index) => {
          const row = checkedFieldList.indexOf(field);
          mergeConf.push({ s: { r: index, c: row + baseColumnIndex }, e: { r: index + span, c: row + baseColumnIndex } });
        });
      } else if (
        field == 'lotId' ||
        field == 'dimensionsSize' ||
        field == 'lotHeight' ||
        field == 'yield' ||
        field == 'markingSum' ||
        field == 'polMarkingSum' ||
        field == 'polPositionExactSum' ||
        field == 'polPositionExactRatio' ||
        field == 'polPatternExactSum' ||
        field == 'polPatternExactRatio' ||
        field == 'polPiantiehouOkSum' ||
        field == 'polPiantiehouOkRatio'
      ) {
        indexSpanMap.lotSpanMap.forEach((span, index) => {
          const row = checkedFieldList.indexOf(field);
          mergeConf.push({ s: { r: index, c: row + baseColumnIndex }, e: { r: index + span, c: row + baseColumnIndex } });
        });
      } else if (field == 'model') {
        indexSpanMap.modelSpanMap.forEach((span, index) => {
          const row = checkedFieldList.indexOf(field);
          mergeConf.push({ s: { r: index, c: row + baseColumnIndex }, e: { r: index + span, c: row + baseColumnIndex } });
        });
      }
    });
  }
  result.mergeConf = mergeConf;
  // 筛选出已选择的字段
  const handleTableData = tableData.map(item => {
    const record = [] as any;
    Object.keys(sortedFieldChecked).forEach(field => {
      record.push(item[field]);
    });
    return record;
  });
  // 添加表头
  const title = [] as any;
  for (let key in sortedFieldChecked) {
    title.push(sortedFieldChecked[key].title);
  }
  handleTableData.unshift(title);
  result.data = handleTableData;
  return result;
};

// marking展开后的数据处理
export const markSlitData = (marklotData: markingBackT) => {
  const datas = [] as marklotDataT[];

  marklotData.lotList?.forEach(lotItem => {
    const baseData = {
      layerId: marklotData.layerId,
      grad: marklotData.grad,
      lotId: lotItem.lotId,
      dimensionsSize: `${lotItem.size}(${lotItem.sizeLong}*${lotItem.sizeShort})`,
      lotHeight: ((lotItem.lotHeight as number) / UNIT_TO_M).toFixed(2), //卷长默认单位为m
      yield: lotItem.yield,
      markingSum: lotItem.markingSum,
      polMarkingSum: lotItem.polMarkingSum,
      polPositionExactSum: lotItem.polPositionExactSum,
      polPositionExactRatio: lotItem.polPositionExactRatio * 100 + '%',
      polPatternExactSum: lotItem.polPatternExactSum,
      polPatternExactRatio: lotItem.polPositionExactRatio * 100 + '%',
      polPiantiehouOkSum: lotItem.polPiantiehouOkSum,
      polPiantiehouOkRatio: lotItem.polPiantiehouOkRatio * 100 + '%'
    };
    lotItem.markingList?.forEach(markingItem => {
      const data = {
        ...baseData,
        key: markingItem.lotId + markingItem.markingId,
        markingExactCount: markingItem.markingExactCount,
        model: getModelByModelId(markingItem.markingId),
        markingType: getMakringNameByMarkingId(markingItem.markingId),
        markingCount: markingItem.markingCount,
        markingExactRatio: markingItem.markingExactRatio * 100 + '%',
        markingOverCount: markingItem.markingOverCount,
        markingOverRatio: markingItem.markingOverRatio * 100 + '%',
        polCheckCount: markingItem.polCheckCount,
        polCheckRatio: markingItem.polCheckRatio * 100 + '%',
        polMissCount: markingItem.polMissCount,
        polMissRatio: markingItem.polMissRatio * 100 + '%',
        piantiehouNgPanelMarkingSum: markingItem.piantiehouNgPanelMarkingSum
      };
      datas.push(data);
    });
  });
  return datas;
};

// 根据modelId查询对应model
export const getModelByModelId = (modelId: number) => {
  let model = '';
  markingStore.allNotGoodFatherMap.forEach((value, key) => {
    if (value.includes(modelId)) {
      model = key;
    }
  });
  return model;
};

export const getMakringNameByMarkingId = (markingId: number) => {
  for (let i = 0; i < markingStore.allNotGoodType.length; i++) {
    for (let j = 0; j < markingStore.allNotGoodType[i]?.children.length; j++) {
      if (markingStore.allNotGoodType[i].children[j].id == markingId) {
        return markingStore.allNotGoodType[i].children[j].markingName;
      }
    }
  }
  return '';
};

// 把缺陷处理成treeData多选的格式
export const getTreeDataType = (flawType: Array<flawTypeCountSymbol>) => {
  const treeDataArr: Array<treeSelectOptionType> = [];
  const siteFatherMap: Map<number, Array<number>> = new Map(); //获取父-对应-子的数组key的map结构
  let flawTypeSymbolMap: Map<number, flawTypeT> = new Map();

  flawType?.forEach(item => {
    if (!item.children || !item.children.length) {
      treeDataArr.push({
        value: item.id,
        title: item.name
      });

      siteFatherMap.set(item.id, []);
      const key1 = item.id;
      const val1 = {
        flawType: item.id,
        name: item.name,
        color: item.color,
        symbol: item.symbol
      };

      flawTypeSymbolMap.set(key1, val1);
    } else {
      const temp1 = [] as Array<treeSelectOptionType>;
      const temp2 = [] as Array<number>;
      item.children.forEach((child: flawTypeCommonT) => {
        temp1.push({
          value: child.id,
          title: child.name
        });
        temp2.push(child.id);
        const key2 = child.id;
        const val2 = {
          flawType: child.id,
          name: child.name,
          color: child.color,
          symbol: child.symbol
        };
        flawTypeSymbolMap.set(key2, val2);
      });

      siteFatherMap.set(item.id, temp2);
      treeDataArr.push({
        value: item.id,
        title: item.name,
        children: temp1
      });
    }
  });

  return {
    modeTreeData: treeDataArr,
    fatherMap: siteFatherMap,
    flawTypeSymbolMap: flawTypeSymbolMap
  };
};

// 单独处理前制程的数据
export const getTreeDataTypeDoff = (flawType: Array<flawTypeCountSymbol>) => {
  const treeDataArr: Array<treeSelectOptionType> = [];
  const siteFatherMap: Map<number, Array<number>> = new Map(); //获取父-对应-子的数组key的map结构
  let flawTypeSymbolMap: Map<number, flawTypeT> = new Map();
  let stationMap: Map<number, Array<number>> = new Map(); // 工位下面的所有子缺陷

  flawType?.forEach((item, index) => {
    // 一个工位下面的
    const stationOne = {
      value: item.id,
      title: item.name,
      children: []
    } as any;
    const stationArrId: Array<number> = [];

    const firstArr = item.children;
    if (!firstArr || !firstArr.length) {
      delete stationOne.children;
      treeDataArr.push(stationOne);
      return;
    }
    firstArr.forEach((first: any) => {
      const fatherFlawType = {
        value: first.id,
        title: first.name
      } as any;
      const childFlawType: Array<treeSelectOptionType> = [];
      const childFlawId: Array<number> = []; // 存饭
      let firstTemp: Array<treeSelectOptionType> = []; //  存放一个工位下面的所有父类缺陷
      if (first.children && first.children.length) {
        first.children.forEach(second => {
          // 最细密度，每个子类缺陷
          childFlawType.push({
            value: second.id,
            title: second.name
          });
          childFlawId.push(second.id);
          const key2 = second.id;
          const val2 = {
            flawType: second.id,
            name: `${first.name}(${second.name})`,
            color: second.color,
            symbol: second.symbol
          };

          flawTypeSymbolMap.set(key2, val2);
        });
        fatherFlawType.children = childFlawType;
        siteFatherMap.set(first.id, childFlawId);
        stationArrId.push(...childFlawId);

        firstTemp.push(fatherFlawType);
        // stationOne.children = firstTemp;
        stationOne.children.push(...firstTemp);
      }
    });
    stationMap.set(item.id, stationArrId);
    treeDataArr.push(stationOne);
  });
  //   console.log('父缺陷Map', siteFatherMap);
  //   console.log('子缺陷铺平Map', flawTypeSymbolMap);
  //   console.log('工位Map', stationMap);
  return {
    modeTreeData: treeDataArr,
    fatherMap: siteFatherMap,
    flawTypeSymbolMap: flawTypeSymbolMap,
    stationMap: stationMap
  };
};

// 当节点有子节点时，不要该节点只要子节点。当该节点无子节点时传入当前节点
export const onlyGetChildFlaw = (checkedFlawType: Array<any>, fatherMap: Map<number, Array<number>>) => {
  const childArr: Array<number> = [];
  checkedFlawType.forEach(key => {
    const valArr = fatherMap.get(key);
    if (valArr && valArr.length !== 0) {
      childArr.push(...valArr);
    } else {
      childArr.push(key);
    }
  });
  return childArr;
};

// 当节点有子节点时，不要该节点只要子节点。当该节点无子节点时传入当前节点
export const onlyGetChildFlawDoff = (checkedFlawType: Array<any>, fatherMap: Map<number, Array<number>>, stationMap: Map<number, Array<number>>) => {
  const childArr: Array<number> = [];
  console.log('doff选中的缺陷处理之前:', checkedFlawType);
  checkedFlawType.forEach(key => {
    const stationArr = stationMap ? stationMap.get(key) : null;
    if (stationArr && stationArr.length !== 0) {
      childArr.push(...stationArr);
    } else {
      const fatherTypeArr = fatherMap ? fatherMap.get(key) : null;
      if (fatherTypeArr && fatherTypeArr.length !== 0) {
        childArr.push(...fatherTypeArr);
      } else {
        childArr.push(key);
      }
    }
  });
  console.log('doff选中的缺陷处理之后:', childArr);
  return childArr;
};

/**
 * 缺陷地图---给缺陷地图的数据，加上缺陷id，对应的color，name，icon，x_y
 * @param flawData
 * @param flawAllMap
 * @param station
 * @param flag
 * @returns
 */
export const giveEchartDataAddFlawInfo = (flawData: Array<flawTypeIdT>, flawAllMap: Map<number, flawTypeT>, station: string) => {
  let echartData = [] as any;
  flawData.forEach(item => {
    const isExit = flawAllMap.get(item.flawType);
    if (isExit) {
      let x = Number(item?.doffCd?.toFixed(2) || 0);
      let y = Number(item?.doffMd?.toFixed(2) || 0) / UNIT_TO_M;

      const val = {
        x_y: [x, y], //后端返回的所有坐标x,y的单位都是mm,但前端需要做处理，Y轴单位是m, X轴单位是mm
        color: isExit.color,
        icon: isExit.symbol,
        name: isExit.name,
        lotId: item?.lotId,
        sheetId: item?.sheetId,
        uid: item?.uid,
        flawType: item?.flawType,
        station: station
      };
      echartData.push(val);
    } else {
      console.log(`${station} 缺陷全集中，不包含这个缺陷：${item.flawType}，会过滤掉不再地图中显示`);
    }
  });
  return echartData;
};

/**
 * 缺陷地图---给seriesData加上icon和颜色，给最新的XY坐标信息,再加上label=字母或形状的颜色
 * @param newArr
 * @returns
 */
export const giveEchartDataAddLableColor = (newArr: Array<echartValT>) => {
  let data = [] as any;
  newArr.forEach((item, index) => {
    const newObj = {
      value: item.x_y,
      icon: item.icon,
      name: item.name,
      label: {
        textStyle: {
          color: item.color
        }
      },
      sheetId: item?.sheetId,
      lotId: item?.lotId,
      uid: item?.uid,
      flawType: item?.flawType,
      station: item?.station
    };
    data.push(newObj);
  });
  return data;
};

/**
 * 综合Map的地图--原始echart
 * @param flawData
 * @param flawAllMap
 * @returns
 */
export const getLayerIdEchartDataDot = (flawData: Array<layerFlawMapDotT>, flawAllMap: Map<number, flawTypeT>) => {
  let echartData = [] as any;
  flawData.forEach(item => {
    const isExit = flawAllMap.get(item.flawType);
    if (isExit) {
      let x = Number(item?.doffCd?.toFixed(2) || 0);
      let y = Number(item?.doffMd?.toFixed(2) || 0) / UNIT_TO_M;
      const val = {
        x_y: [x, y], //后端返回的所有坐标x,y的单位都是mm,但前端需要做处理，Y轴单位是m, X轴单位是mm
        color: isExit.color,
        icon: isExit.symbol,
        name: isExit.name,
        lotId: item.lotId,
        flawType: item.flawType
      };
      echartData.push(val);
    }
  });
  return echartData;
};

/**
 * 综合Map的地图-echart + 颜色形状文字
 * @param newArr
 * @returns
 */
export const getLayerIdAddLableColor = (newArr: Array<layerFlawMapEchartValT>) => {
  let data = [] as any;
  newArr.forEach((item, index) => {
    const newObj = {
      value: item.x_y,
      icon: item.icon,
      name: item.name,
      label: {
        textStyle: {
          color: item.color
        }
      },
      lotId: item.lotId,
      flawType: item.flawType
    };
    data.push(newObj);
  });
  return data;
};

/**
 * 计算卷的 X Y 轴的开始坐标和结束坐标
 * @param doffCd
 * @param doffMd
 * @param width
 * @param height
 */
export const getEchartAxis = (type: flawMapT, doffCd: number, doffMd: number, width: number, height: number, qrMd?: number) => {
  //   console.log(type, '=========>', doffCd, doffMd, width, height);
  let result = {
    xMin: 0,
    xMax: 0,
    yMin: 0,
    yMax: 0,
    qrMin: 0,
    qrMax: 0
  };

  let unitY = 1;
  if (type == flawMapT.lot) {
    unitY = 1000;
  }

  if (doffCd || doffCd == 0) {
    result.xMin = Math.floor(doffCd);
    if (width) {
      result.xMax = Math.round(doffCd + width);
    } else {
      result.xMax = Math.round(doffCd);
    }
  }

  if (doffMd || doffMd == 0) {
    result.yMin = Math.floor(doffMd / unitY);
    if (height) {
      result.yMax = Math.round((doffMd + height) / unitY);
    } else {
      result.yMax = Math.round(doffMd / unitY);
    }
  }
  if (qrMd || qrMd == 0) {
    result.qrMin = Math.floor(qrMd / unitY);
    if (height) {
      result.qrMax = Math.round((qrMd + height) / unitY);
    } else {
      result.qrMax = Math.round(qrMd / unitY);
    }
  }

  return result;
};
